package com.ushine.web.base.controller;


import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.security.utils.RsaKeyConfig;
import io.swagger.annotations.Api;
import org.apache.commons.codec.binary.Base64;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.PublicKey;

/**
 * @Author yls
 * @Date 2020/4/5 12:21
 * @Description 登录控制器
 * @Version 1.0
 **/
@RestController
@Api(tags = "基础模块-登录")
@RequestMapping("system/login")
public class LoginController {

    @Resource
    RsaKeyConfig rsaKeyConfig;

    /**
     * 功能描述
     * (前台密码加密的公钥)
     *
     * @return : com.ushine.component.http.HttpResponseVO
     * @author : yls
     * @date : 2021/3/16 14:39
     */
    @GetMapping("genKeyPair")
    public HttpResponseVO<String> genKeyPair() {
        PublicKey publicKey = rsaKeyConfig.getPublicKey();
        String publicKeyStr = new String(Base64.encodeBase64((publicKey.getEncoded())));
        return new HttpResponseVO<String>().ok("ok", publicKeyStr);
    }

}
